﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace XDesigner.ORM.Test
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            //ORMCodeGenerator.GenareteCode2(@"E:\Source\XDesignerORM\ORM\Test\CustomerClassORMTypeMappingHelper.cs", "c:\\a.cs");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());
        }

        public static System.Data.IDbConnection CreateConnection()
        {
            System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
            conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\""
                + System.IO.Path.Combine(Application.StartupPath, "SkyDemo.mdb") + "\"";
            return conn;
        }

        private static ORMEngine myORM = null;
        public static ORMEngine ORM
        {
            get
            {
                if (myORM == null)
                {
                    myORM = new ORMEngine(CreateConnection());
                    myORM.Config.DebugMode = true;
                    myORM.Config.BufferLevel = ORMBufferLevel.Both;
                    myORM.Config.UpdateImmediately = true;

                    myORM.AddType(typeof(CustomerClass));

                    //myORM.SetHelper(typeof(OrderClass), new OrderClassORMTypeMappingHelper());
                    //myORM.SetHelper(typeof(EmployeeClass), new EmployeeClassORMTypeMappingHelper());
                    //myORM.SetHelper(typeof(OrderDetailClass), new OrderDetailClassORMTypeMappingHelper());
                    //myORM.SetHelper(typeof(ProductClass), new ProductClassORMTypeMappingHelper());
                    //myORM.SetHelper(typeof(SupplierClass), new SupplierClassORMTypeMappingHelper());

                    //myORM.SetHelper(typeof(CustomerClass), new CustomerClassORMTypeMappingHelper());
                    
                    myORM.OpenConnectionEvent += new ORMEventHandler(myORM_OpenConnectionEvent);
                }
                return myORM;
            }
        }

        static void myORM_OpenConnectionEvent(object sender, ORMEventArgs args)
        {
            args.Result = CreateConnection();
        }

    }
}